using BasicScript.Component;
using Game.Core;
using Game.Main.Model;
using Game.Manager;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class TVBItem : BaseItem
	{
		public int state;

		private FrameAnimation frameAnim;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			Transform transform = model.Find("Light");
			frameAnim = transform.GetComponent<FrameAnimation>();
			SetState(data.state);
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			if (!(frameAnim == null))
			{
				if (state == 0)
				{
					frameAnim.Stop();
					state = frameAnim.curFrame + 1;
				}
				else
				{
					frameAnim.Continue();
					state = 0;
				}
				Singleton<AudioManager>.Instance.PlaySound("sound_btn_1");
			}
		}

		public void SetState(int val)
		{
			if (state != val)
			{
				state = val;
				if (state == 0)
				{
					frameAnim.Continue();
					return;
				}
				frameAnim.Stop();
				frameAnim.JumpToFrame(state - 1);
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = state;
		}
	}
}
